import request from '@/utils/request';

// 星球数据接口
export interface PlanetItem {
  id: number;
  create_time: string;
  update_time: string;
  planet_name: string;
  radius: number;
  planet_name_zh: string;
  origin_img: string;
  output_img: string;
  planet_img_level: number;
  planet_img_type: number;
  planet_img_size: number;
  is_default?: number;
}

// 地点数据接口
export interface LocationItem {
  id: number;
  create_time: string;
  update_time: string;
  planet_id: number;
  location_name: string;
  location_name_zh: string;
  approval_date: string;
  location_race: string;
  location_type: string;
  location_diameter: number;
  location_level: number;
  location_name_origin: string;
  center_latitude: number | null;
  center_longitude: number | null;
}

// 星球列表查询参数
export interface PlanetListParams {
  planet_name?: string;
  page?: number;
  page_size?: number;
}

// 地点列表查询参数
export interface LocationListParams {
  planet_id?: number;
  location_name?: string;
  location_name_zh?: string;
  location_type?: string;
  location_level?: number;
  approval_date_lte?: string;
  approval_date_gte?: string;
  location_race?: string;
  location_diameter?: number;
  location_name_origin?: string;
  center_latitude?: number;
  center_longitude?: number;
  page?: number;
  page_size?: number;
}

// 星球列表响应
export interface PlanetListResponse {
  code: number;
  msg: string;
  data: {
    count: number;
    list: PlanetItem[];
    page: number;
    pages: number;
    page_size: number;
  };
}

// 地点列表响应
export interface LocationListResponse {
  code: number;
  msg: string;
  data: {
    count: number;
    list: LocationItem[];
    page: number;
    pages: number;
    page_size: number;
  };
}

// 新建星球参数
export interface CreatePlanetParams {
  planet_name: string;
  planet_name_zh: string;
  radius: number;
}

// 新建地点参数
export interface CreateLocationParams {
  planet_id: number;
  location_name: string;
  location_name_zh: string;
  approval_date: string;
  location_race: string;
  location_type: string;
  location_diameter: number;
  location_level: number;
  location_name_origin: string;
  center_latitude?: number;
  center_longitude?: number;
}

// 新建星球响应
export interface CreatePlanetResponse {
  code: number;
  msg: string;
  data: PlanetItem;
}

// 新建地点响应
export interface CreateLocationResponse {
  code: number;
  msg: string;
  data: LocationItem;
}

// 修改星球参数
export interface UpdatePlanetParams {
  id: number;
  planet_name: string;
  planet_name_zh: string;
  radius: number;
}

// 修改地点参数
export interface UpdateLocationParams {
  id: number;
  planet_id: number;
  location_name: string;
  location_name_zh: string;
  approval_date: string;
  location_race: string;
  location_type: string;
  location_diameter: number;
  location_level: number;
  location_name_origin: string;
  center_latitude?: number;
  center_longitude?: number;
}

// 删除星球参数
export interface DeletePlanetParams {
  id: number;
}

// 删除地点参数
export interface DeleteLocationParams {
  id_list: number[];
}

// 星球底图上传参数
export interface UploadPlanetImageParams {
  file: File;
  planet_id: number;
}

// 通用响应接口
export interface CommonResponse {
  code: number;
  msg: string;
  data: any;
}

// 获取星球详情参数
export interface GetPlanetInfoParams {
  id: number;
}

// 获取星球详情响应
export interface GetPlanetInfoResponse {
  code: number;
  msg: string;
  data: PlanetItem;
}

// 获取星球列表
export const getPlanetList = async (params: PlanetListParams = {}): Promise<PlanetListResponse> => {
  try {
    const response = await request.get('/GIS/GISPlanet', {
      params
    });
    return response.data;
  } catch (error) {
    console.error('获取星球列表失败:', error);
    throw error;
  }
};

// 获取星球详情
export const getPlanetInfo = async (params: GetPlanetInfoParams): Promise<GetPlanetInfoResponse> => {
  try {
    const response = await request.get('/GIS/GISPlanetInfo', {
      params
    });
    return response.data;
  } catch (error) {
    console.error('获取星球详情失败:', error);
    throw error;
  }
};

// 获取地点列表
export const getLocationList = async (params: LocationListParams = {}): Promise<LocationListResponse> => {
  try {
    const response = await request.get('/GIS/GISLocation', {
      params
    });
    // 转换经纬度字段为数字类型
    if (response.data?.data?.list) {
      response.data.data.list = response.data.data.list.map((item: any) => ({
        ...item,
        left_latitude: typeof item.left_latitude === 'string' ? parseFloat(item.left_latitude) : item.left_latitude,
        left_longitude: typeof item.left_longitude === 'string' ? parseFloat(item.left_longitude) : item.left_longitude,
        right_latitude: typeof item.right_latitude === 'string' ? parseFloat(item.right_latitude) : item.right_latitude,
        right_longitude: typeof item.right_longitude === 'string' ? parseFloat(item.right_longitude) : item.right_longitude,
        center_latitude: typeof item.center_latitude === 'string' ? parseFloat(item.center_latitude) : item.center_latitude,
        center_longitude: typeof item.center_longitude === 'string' ? parseFloat(item.center_longitude) : item.center_longitude,
      }));
    }
    return response.data;
  } catch (error) {
    console.error('获取地点列表失败:', error);
    throw error;
  }
};

// 新建星球
export const createPlanet = async (params: CreatePlanetParams): Promise<CreatePlanetResponse> => {
  try {
    const response = await request('/GIS/GISPlanet', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('新建星球失败:', error);
    throw error;
  }
};

// 新建地点
export const createLocation = async (params: CreateLocationParams): Promise<CreateLocationResponse> => {
  try {
    const response = await request('/GIS/GISLocation', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('新建地点失败:', error);
    throw error;
  }
};

// 修改星球
export const updatePlanet = async (params: UpdatePlanetParams): Promise<CommonResponse> => {
  try {
    const response = await request('/GIS/GISPlanetUpdate', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('修改星球失败:', error);
    throw error;
  }
};

// 修改地点
export const updateLocation = async (params: UpdateLocationParams): Promise<CommonResponse> => {
  try {
    const response = await request('/GIS/GISLocationUpdate', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('修改地点失败:', error);
    throw error;
  }
};

// 删除星球
export const deletePlanet = async (params: DeletePlanetParams): Promise<CommonResponse> => {
  try {
    const response = await request('/GIS/GISPlanetDelete', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('删除星球失败:', error);
    throw error;
  }
};

// 删除地点
export const deleteLocation = async (params: DeleteLocationParams): Promise<CommonResponse> => {
  try {
    const response = await request('/GIS/GISLocationDelete', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('删除地点失败:', error);
    throw error;
  }
};

// 上传星球底图
export const uploadPlanetImage = async (params: UploadPlanetImageParams): Promise<CommonResponse> => {
  try {
    const formData = new FormData();
    formData.append('file', params.file);
    formData.append('planet_id', params.planet_id.toString());
    
    const response = await request('/GIS/GISPlanetIMGUpload', {
      method: 'POST',
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data',
      },
    });
    return response.data;
  } catch (error) {
    console.error('上传星球底图失败:', error);
    throw error;
  }
};

// 空间数据管理相关接口
export interface DataAreaItem {
  id: number;
  planet_id: number;
  task: string;
  task_zh: string;
  data_type: string;
  data_level: string;
  area_level: string;
  area_name: string;
  left_latitude: number;
  left_longitude: number;
  right_latitude: number;
  right_longitude: number;
  files: string;
  create_time: string;
  update_time: string;
}

export interface DataAreaListParams {
  planet_id: number;
  page?: number;
  page_size?: number;
  task?: string;
  task_zh?: string;
  data_type?: string;
  data_level?: string;
  area_level?: string;
  area_name?: string;
  left_latitude?: number;
  left_longitude?: number;
  right_latitude?: number;
  right_longitude?: number;
}

export interface DataAreaListResponse {
  code: number;
  msg: string;
  data: {
    count: number;
    list: DataAreaItem[];
    page: number;
    pages: number;
    page_size: number;
  };
}

export interface CreateDataAreaParams {
  planet_id: number;
  task: string;
  task_zh: string;
  data_type: string;
  data_level: string;
  area_level: string;
  area_name: string;
  left_latitude: number;
  left_longitude: number;
  right_latitude: number;
  right_longitude: number;
  files: string;
}

export interface CreateDataAreaResponse {
  code: number;
  msg: string;
  data: DataAreaItem;
}

export interface UpdateDataAreaParams {
  id: number;
  planet_id: number;
  task: string;
  task_zh: string;
  data_type: string;
  data_level: string;
  area_level: string;
  area_name: string;
  left_latitude: number;
  left_longitude: number;
  right_latitude: number;
  right_longitude: number;
  files: string;
}

export interface DeleteDataAreaParams {
  id_list: number[];
}

// 空间数据管理API函数
export const getDataAreaList = async (params: Partial<DataAreaListParams> = {}): Promise<DataAreaListResponse> => {
  try {
    const response = await request.get('/GIS/GISDataArea', {
      params
    });
    // 转换经纬度字段为数字类型
    if (response.data?.data?.list) {
      response.data.data.list = response.data.data.list.map((item: any) => ({
        ...item,
        left_latitude: typeof item.left_latitude === 'string' ? parseFloat(item.left_latitude) : item.left_latitude,
        left_longitude: typeof item.left_longitude === 'string' ? parseFloat(item.left_longitude) : item.left_longitude,
        right_latitude: typeof item.right_latitude === 'string' ? parseFloat(item.right_latitude) : item.right_latitude,
        right_longitude: typeof item.right_longitude === 'string' ? parseFloat(item.right_longitude) : item.right_longitude,
      }));
    }
    return response.data;
  } catch (error) {
    console.error('获取数据区域列表失败:', error);
    throw error;
  }
};

export const createDataArea = async (params: CreateDataAreaParams): Promise<CreateDataAreaResponse> => {
  try {
    const response = await request('/GIS/GISDataArea', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('新建数据区域失败:', error);
    throw error;
  }
};

export const updateDataArea = async (params: UpdateDataAreaParams): Promise<CommonResponse> => {
  try {
    const response = await request('/GIS/GISDataAreaUpdate', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('修改数据区域失败:', error);
    throw error;
  }
};

export const deleteDataArea = async (params: DeleteDataAreaParams): Promise<CommonResponse> => {
  try {
    const response = await request('/GIS/GISDataAreaDelete', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('删除数据区域失败:', error);
    throw error;
  }
};

// 探测点管理相关接口
export interface DetectionPointItem {
  id: number;
  planet_id: number;
  detection_time: string;
  task: string;
  task_zh: string;
  data_type: string;
  data_level: string;
  detection_name: string;
  latitude: number;
  longitude: number;
  files: string;
  create_time: string;
  update_time: string;
}

export interface DetectionPointListParams {
  planet_id: number;
  page?: number;
  page_size?: number;
  task?: string;
  task_zh?: string;
  data_type?: string;
  data_level?: string;
  detection_name?: string;
  latitude?: number;
  longitude?: number;
  detection_time__lte?: string;
  detection_time__gte?: string;
}

export interface DetectionPointListResponse {
  code: number;
  msg: string;
  data: {
    count: number;
    list: DetectionPointItem[];
    page: number;
    pages: number;
    page_size: number;
  };
}

export interface CreateDetectionPointParams {
  planet_id: number;
  detection_time: string;
  task: string;
  task_zh: string;
  data_type: string;
  data_level: string;
  detection_name: string;
  latitude: number;
  longitude: number;
  files: string;
}

export interface CreateDetectionPointResponse {
  code: number;
  msg: string;
  data: DetectionPointItem;
}

export interface UpdateDetectionPointParams {
  id: number;
  planet_id: number;
  detection_time: string;
  task: string;
  task_zh: string;
  data_type: string;
  data_level: string;
  detection_name: string;
  latitude: number;
  longitude: number;
  files: string;
}

export interface DeleteDetectionPointParams {
  id_list: number[];
}

// 探测点管理API函数
export const getDetectionPointList = async (params: Partial<DetectionPointListParams> = {}): Promise<DetectionPointListResponse> => {
  try {
    const response = await request.get('/GIS/GISDetectionPoint', {
      params
    });
    // 转换经纬度字段为数字类型
    if (response.data?.data?.list) {
      response.data.data.list = response.data.data.list.map((item: any) => ({
        ...item,
        latitude: typeof item.latitude === 'string' ? parseFloat(item.latitude) : item.latitude,
        longitude: typeof item.longitude === 'string' ? parseFloat(item.longitude) : item.longitude,
      }));
    }
    return response.data;
  } catch (error) {
    console.error('获取探测点列表失败:', error);
    throw error;
  }
};

export const createDetectionPoint = async (params: CreateDetectionPointParams): Promise<CreateDetectionPointResponse> => {
  try {
    const response = await request('/GIS/GISDetectionPoint', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('新建探测点失败:', error);
    throw error;
  }
};

export const updateDetectionPoint = async (params: UpdateDetectionPointParams): Promise<CommonResponse> => {
  try {
    const response = await request('/GIS/GISDetectionPointUpdate', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('修改探测点失败:', error);
    throw error;
  }
};

export const deleteDetectionPoint = async (params: DeleteDetectionPointParams): Promise<CommonResponse> => {
  try {
    const response = await request('/GIS/GISDetectionPointDelete', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('删除探测点失败:', error);
    throw error;
  }
}; 

// 地点批量上传参数
export interface LocationBatchUploadParams {
  file: File;
  planet_id: number;
}

// 地点批量上传响应
export interface LocationBatchUploadResponse {
  code: number;
  msg: string;
  data: {
    success_count: number;
    fail_count: number;
    total_count: number;
    errors?: string[];
  };
}

// 地点批量上传
export const locationBatchUpload = async (params: LocationBatchUploadParams): Promise<LocationBatchUploadResponse> => {
  try {
    const formData = new FormData();
    formData.append('file', params.file);
    formData.append('planet_id', params.planet_id.toString());
    
    const response = await request('/GIS/GISLocationBatchUpload', {
      method: 'POST',
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data',
      },
    });
    return response.data;
  } catch (error) {
    console.error('地点批量上传失败:', error);
    throw error;
  }
}; 

// 数据区域批量上传参数
export interface DataAreaBatchUploadParams {
  file: File;
  planet_id: number;
}

// 数据区域批量上传响应
export interface DataAreaBatchUploadResponse {
  code: number;
  msg: string;
  data: {
    success_count: number;
    fail_count: number;
    total_count: number;
    errors?: string[];
  };
}

// 数据区域批量上传
export const dataAreaBatchUpload = async (params: DataAreaBatchUploadParams): Promise<DataAreaBatchUploadResponse> => {
  try {
    const formData = new FormData();
    formData.append('file', params.file);
    formData.append('planet_id', params.planet_id.toString());
    
    const response = await request('/GIS/GISDataAreaBatchUpload', {
      method: 'POST',
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data',
      },
    });
    return response.data;
  } catch (error) {
    console.error('数据区域批量上传失败:', error);
    throw error;
  }
}; 

// 探测点批量上传参数
export interface DetectionPointBatchUploadParams {
  file: File;
  planet_id: number;
}

// 探测点批量上传响应
export interface DetectionPointBatchUploadResponse {
  code: number;
  msg: string;
  data: {
    success_count: number;
    fail_count: number;
    total_count: number;
    errors?: string[];
  };
}

// 探测点批量上传
export const detectionPointBatchUpload = async (params: DetectionPointBatchUploadParams): Promise<DetectionPointBatchUploadResponse> => {
  try {
    const formData = new FormData();
    formData.append('file', params.file);
    formData.append('planet_id', params.planet_id.toString());
    
    const response = await request('/GIS/GISDetectionPointBatchUpload', {
      method: 'POST',
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data',
      },
    });
    return response.data;
  } catch (error) {
    console.error('探测点批量上传失败:', error);
    throw error;
  }
}; 

// 星球底图信息接口
export interface PlanetImageItem {
  id: number;
  planet_id: number;
  image_url: string;
  image_name: string;
  image_size: number;
  upload_time: string;
  image_type: string;
  create_time: string;
  update_time: string;
}

// 获取星球底图列表参数
export interface PlanetImageListParams {
  planet_id: number;
  page?: number;
  page_size?: number;
  image_type?: string;
}

// 获取星球底图列表响应
export interface PlanetImageListResponse {
  code: number;
  msg: string;
  data: {
    count: number;
    list: PlanetImageItem[];
    page: number;
    pages: number;
    page_size: number;
  };
}

// 删除星球底图参数
export interface DeletePlanetImageParams {
  id_list: number[];
}

// 获取星球底图列表
export const getPlanetImageList = async (params: Partial<PlanetImageListParams> = {}): Promise<PlanetImageListResponse> => {
  try {
    const response = await request.get('/GIS/GISPlanetImageList', {
      params
    });
    return response.data;
  } catch (error) {
    console.error('获取星球底图列表失败:', error);
    throw error;
  }
};

// 删除星球底图
export const deletePlanetImage = async (params: DeletePlanetImageParams): Promise<CommonResponse> => {
  try {
    const response = await request('/GIS/GISPlanetImageDelete', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('删除星球底图失败:', error);
    throw error;
  }
}; 

// 设置默认星球参数
export interface SetDefaultPlanetParams {
  id: number;
}

// 设置默认星球
export const setDefaultPlanet = async (params: SetDefaultPlanetParams): Promise<CommonResponse> => {
  try {
    const response = await request('/GIS/GISPlanetSetDefault', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('设置默认星球失败:', error);
    throw error;
  }
}; 

// 设置星球底图上传类型（JPG/TIF）参数
export interface SetPlanetUploadTypeParams {
  id: number; // 星球id
  planet_img_type: number; // 1: JPG, 2: TIF
  output_img?: string; // 当 planet_img_type 为 2 时必传：TIF地址
}

// 设置星球底图上传类型（JPG/TIF）
export const setPlanetUploadType = async (params: SetPlanetUploadTypeParams): Promise<CommonResponse> => {
  try {
    const response = await request('/GIS/GISPlanetSetUploadType', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('设置星球图片上传类型失败:', error);
    throw error;
  }
};

// 空间数据管理树相关接口
export interface GISDataAreaTreeItem {
  task_name: string;
  data_set_list: Array<{
    data_set_name: string;
    key: string;
  }>;
}

export interface GISDataAreaTreeResponse {
  code: number;
  msg: string;
  data: GISDataAreaTreeItem[];
}

export interface GISDataAreaTreeSaveParams {
  planet_id: number;
  action_type: 'create' | 'update' | 'delete';
  tree_uuid?: string; // 删除时必传
  tree: GISDataAreaTreeItem[];
}

export interface GISDataAreaTreeSaveResponse {
  code: number;
  msg: string;
  data: {};
}

// 获取空间数据管理左侧树
export const getGISDataAreaTree = async (params: { planet_id: number }): Promise<GISDataAreaTreeResponse> => {
  try {
    const response = await request.get('/GIS/GISDataAreaTree', {
      params
    });
    return response.data;
  } catch (error) {
    console.error('获取空间数据管理树失败:', error);
    throw error;
  }
};

// 空间数据管理左侧树新增/保存
export const saveGISDataAreaTree = async (params: GISDataAreaTreeSaveParams): Promise<GISDataAreaTreeSaveResponse> => {
  try {
    const response = await request('/GIS/GISDataAreaTreeSave', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('保存空间数据管理树失败:', error);
    throw error;
  }
};

// 新的探测点管理相关接口
// 巡视区数据接口
export interface InspectionAreaItem {
  id: number;
  inspection_area_name: string;
  task: string;
  create_time: string;
  left_latitude: number;
  left_longitude: number;
  right_latitude: number;
  right_longitude: number;
  base_image_path: string;
}

// 探测点数据接口
export interface DetectionPointNewItem {
  id: number;
  inspection_area_id: number;
  create_time: string;
  update_time: string;
  detection_strat_time: string;
  detection_end_time: string;
  planet_id: number;
  detection_name: string;
  detection_num: string;
  center_latitude: number;
  center_longitude: number;
  is_special: number;
}

// 数据集数据接口
export interface DataSetItem {
  id: number;
  inspection_area_id: number;
  detection_point_id: number;
  create_time: string;
  update_time: string;
  planet_id: number;
  data_set_name: string;
  file_count: number;
  file_sizes: number;
}

// 探测点管理树结构接口
export interface DetectionPointTreeItem {
  inspection_area_name: string;
  inspection_area_id: number;
  detection_point_list: Array<{
    detection_point_num: string;
    detection_point_id: number;
    data_set_list: Array<{
      data_set_name: string;
      data_set_id: number;
    }>;
  }>;
}

// 巡视区列表参数
export interface InspectionAreaListParams {
  planet_id: number;
  page?: number;
  page_size?: number;
}

// 巡视区列表响应
export interface InspectionAreaListResponse {
  code: number;
  msg: string;
  data: {
    count: number;
    list: InspectionAreaItem[];
    page: number;
    pages: number;
    page_size: number;
  };
}

// 巡视区创建/更新参数
export interface InspectionAreaCreateParams {
  planet_id: number;
  inspection_area_name: string;
  task: string;
  left_latitude: number;
  left_longitude: number;
  right_latitude: number;
  right_longitude: number;
  base_image_path: string;
}

export interface InspectionAreaUpdateParams extends InspectionAreaCreateParams {
  inspection_area_id: number;
}

// 巡视区删除参数
export interface InspectionAreaDeleteParams {
  planet_id: number;
  inspection_area_ids: number[];
}

// 探测点列表参数
export interface DetectionPointNewListParams {
  inspection_area_id: number;
  page?: number;
  page_size?: number;
}

// 探测点列表响应
export interface DetectionPointNewListResponse {
  code: number;
  msg: string;
  data: {
    count: number;
    list: DetectionPointNewItem[];
    page: number;
    pages: number;
    page_size: number;
  };
}

// 探测点创建/更新参数
export interface DetectionPointNewCreateParams {
  planet_id: number;
  inspection_area_id: number;
  detection_name: string;
  detection_num: string;
  detection_strat_time: string;
  detection_end_time: string;
  center_latitude: number;
  center_longitude: number;
  is_special: number;
}

export interface DetectionPointNewUpdateParams extends DetectionPointNewCreateParams {
  detection_point_id: number;
}

// 探测点删除参数
export interface DetectionPointNewDeleteParams {
  ids: number[];
}

// 探测点批量创建参数
export interface DetectionPointBatchCreateParams {
  planet_id: number;
  inspection_area_id: number;
  file: File;
}

// 数据集列表参数
export interface DataSetListParams {
  planet_id: number;
  inspection_area_id: number;
  detection_point_id: number;
  page?: number;
  page_size?: number;
}

// 数据集列表响应
export interface DataSetListResponse {
  code: number;
  msg: string;
  data: {
    count: number;
    list: DataSetItem[];
    page: number;
    pages: number;
    page_size: number;
  };
}

// 数据集全量名称（去重）查询参数
export interface DataSetAllNameParams {
  planet_id: number;
}

// 数据集全量名称（去重）响应
export interface DataSetAllNameResponse {
  code: number;
  msg: string;
  data: {
    data_set_names: string[];
  };
}

// 数据集创建参数
export interface DataSetCreateParams {
  planet_id: number;
  inspection_area_id: number;
  detection_point_id: number;
  data_set_name: string;
}

// 数据集更新参数（按后端规范：仅 id 与 data_set_name）
export interface DataSetUpdateParams {
  id: number;
  data_set_name: string;
}

// 数据集删除参数（按后端规范：仅 ids）
export interface DataSetDeleteParams {
  ids: number[];
}

// 探测点管理树响应
export interface DetectionPointTreeResponse {
  code: number;
  msg: string;
  data: DetectionPointTreeItem[];
}

// 新的探测点管理API函数
// 获取探测点管理左侧目录树
export const getDetectionPointTree = async (params: { planet_id: number }): Promise<DetectionPointTreeResponse> => {
  try {
    const response = await request.get('/GIS/GISDetectionPointTree', {
      params
    });
    // 转换经纬度字段为数字类型
    if (response.data?.data) {
      response.data.data = response.data.data.map((item: any) => ({
        ...item,
        detection_point_list: item.detection_point_list?.map((dp: any) => ({
          ...dp,
          center_latitude: typeof dp.center_latitude === 'string' ? parseFloat(dp.center_latitude) : dp.center_latitude,
          center_longitude: typeof dp.center_longitude === 'string' ? parseFloat(dp.center_longitude) : dp.center_longitude,
        })),
      }));
    }
    return response.data;
  } catch (error) {
    console.error('获取探测点管理树失败:', error);
    throw error;
  }
};

// 获取巡视区列表
export const getInspectionAreaList = async (params: InspectionAreaListParams): Promise<InspectionAreaListResponse> => {
  try {
    const response = await request.get('/GIS/GISDetectionPointInspectionArea', {
      params
    });
    // 转换经纬度字段为数字类型
    if (response.data?.data?.list) {
      response.data.data.list = response.data.data.list.map((item: any) => ({
        ...item,
        left_latitude: typeof item.left_latitude === 'string' ? parseFloat(item.left_latitude) : item.left_latitude,
        left_longitude: typeof item.left_longitude === 'string' ? parseFloat(item.left_longitude) : item.left_longitude,
        right_latitude: typeof item.right_latitude === 'string' ? parseFloat(item.right_latitude) : item.right_latitude,
        right_longitude: typeof item.right_longitude === 'string' ? parseFloat(item.right_longitude) : item.right_longitude,
      }));
    }
    return response.data;
  } catch (error) {
    console.error('获取巡视区列表失败:', error);
    throw error;
  }
};

// 创建巡视区
export const createInspectionArea = async (params: InspectionAreaCreateParams): Promise<CommonResponse> => {
  try {
    const response = await request('/GIS/GISDetectionPointInspectionAreaCreate', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('创建巡视区失败:', error);
    throw error;
  }
};

// 更新巡视区
export const updateInspectionArea = async (params: InspectionAreaUpdateParams): Promise<CommonResponse> => {
  try {
    const response = await request('/GIS/GISDetectionPointInspectionAreaUpdate', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('更新巡视区失败:', error);
    throw error;
  }
};

// 删除巡视区
export const deleteInspectionArea = async (params: InspectionAreaDeleteParams): Promise<CommonResponse> => {
  try {
    const response = await request('/GIS/GISDetectionPointInspectionAreadelete', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('删除巡视区失败:', error);
    throw error;
  }
};

// 获取探测点列表
export const getDetectionPointNewList = async (params: DetectionPointNewListParams): Promise<DetectionPointNewListResponse> => {
  try {
    const response = await request.get('/GIS/GISDetectionPoint', {
      params
    });
    // 转换经纬度字段为数字类型
    if (response.data?.data?.list) {
      response.data.data.list = response.data.data.list.map((item: any) => ({
        ...item,
        center_latitude: typeof item.center_latitude === 'string' ? parseFloat(item.center_latitude) : item.center_latitude,
        center_longitude: typeof item.center_longitude === 'string' ? parseFloat(item.center_longitude) : item.center_longitude,
      }));
    }
    return response.data;
  } catch (error) {
    console.error('获取探测点列表失败:', error);
    throw error;
  }
};

// 创建探测点
export const createDetectionPointNew = async (params: DetectionPointNewCreateParams): Promise<CommonResponse> => {
  try {
    const response = await request('/GIS/GISDetectionPointCreate', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('创建探测点失败:', error);
    throw error;
  }
};

// 更新探测点
export const updateDetectionPointNew = async (params: DetectionPointNewUpdateParams): Promise<CommonResponse> => {
  try {
    // 兼容后端参数命名：将 detection_point_id 映射为 id
    const { detection_point_id, ...rest } = params;
    const payload = { id: detection_point_id, ...rest };
    const response = await request('/GIS/GISDetectionPointUpdate', {
      method: 'POST',
      data: payload
    });
    return response.data;
  } catch (error) {
    console.error('更新探测点失败:', error);
    throw error;
  }
};

// 删除探测点
export const deleteDetectionPointNew = async (params: DetectionPointNewDeleteParams): Promise<CommonResponse> => {
  try {
    const response = await request('/GIS/GISDetectionPointDelete', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('删除探测点失败:', error);
    throw error;
  }
};

// 批量创建探测点
export const batchCreateDetectionPoint = async (params: DetectionPointBatchCreateParams): Promise<CommonResponse> => {
  try {
    const formData = new FormData();
    formData.append('file', params.file);
    formData.append('planet_id', params.planet_id.toString());
    formData.append('inspection_area_id', params.inspection_area_id.toString());
    
    const response = await request('/GIS/GISDetectionPointBatchCreate', {
      method: 'POST',
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data',
      },
    });
    return response.data;
  } catch (error) {
    console.error('批量创建探测点失败:', error);
    throw error;
  }
};

// 获取数据集列表
export const getDataSetList = async (params: DataSetListParams): Promise<DataSetListResponse> => {
  try {
    const response = await request.get('/GIS/GISDetectionPointDataSet', {
      params
    });
    return response.data;
  } catch (error) {
    console.error('获取数据集列表失败:', error);
    throw error;
  }
};

// 获取所有数据集名称（去重）
export const getDetectionPointDataSetAllName = async (
  params: DataSetAllNameParams
): Promise<DataSetAllNameResponse> => {
  try {
    const response = await request.get('/GIS/GISDetectionPointDataSetAllName', {
      params
    });
    return response.data;
  } catch (error) {
    console.error('获取数据集名称列表失败:', error);
    throw error;
  }
};

// 创建数据集
export const createDataSet = async (params: DataSetCreateParams): Promise<CommonResponse> => {
  try {
    const response = await request('/GIS/GISDetectionPointDataSetCreate', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('创建数据集失败:', error);
    throw error;
  }
};

// 更新数据集
export const updateDataSet = async (params: DataSetUpdateParams): Promise<CommonResponse> => {
  try {
    const response = await request('/GIS/GISDetectionPointDataSetUpdate', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('更新数据集失败:', error);
    throw error;
  }
};

// 删除数据集
export const deleteDataSet = async (params: DataSetDeleteParams): Promise<CommonResponse> => {
  try {
    const response = await request('/GIS/GISDetectionPointDataSetDelete', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('删除数据集失败:', error);
    throw error;
  }
};

// 批量创建数据集
export interface DataSetBatchCreateParams {
  planet_id: number;
  inspection_area_id: number;
  detection_point_id: number;
  data_set_names: string[];
}

export const batchCreateDataSet = async (
  params: DataSetBatchCreateParams
): Promise<CommonResponse> => {
  try {
    const response = await request('/GIS/GISDetectionPointDataSetBatchCreate', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('批量创建数据集失败:', error);
    throw error;
  }
};

// 探测点数据集文件管理接口
export interface DetectionPointDataSetFileItem {
  id: number;
  create_time: string;
  update_time: string;
  planet_id: number;
  inspection_area_id: number;
  detection_point_id: number;
  data_set_id: number;
  product_id: number;
  data_type: string;
  task: string;
  file_name: string;
  file_path: string;
  collection_time_start: string;
  collection_time_end: string;
  archive_time: string;
  data_size: number;
  station: string;
  dm_zhname: string; // 载荷
  data_level: string; // 数据等级
  version_num: string;
  track_num_turns: number;
}

export interface DetectionPointDataSetFileListParams {
  data_set_id: number;
  page?: number;
  page_size?: number;
}

export interface DetectionPointDataSetFileListResponse {
  code: number;
  msg: string;
  data: {
    count: number;
    list: DetectionPointDataSetFileItem[];
    page: number;
    pages: number;
    page_size: number;
  };
}

export interface DetectionPointDataSetFileCreateParams {
  planet_id: number; // 星球id
  inspection_area_id: number; // 数据区域id
  detection_point_id: number; // 探测点id
  data_set_id: number; // 数据集id
  files: Array<{
    data_type: string; // 数据类型
    product_id: number;
  }>;
}

export interface DetectionPointDataSetFileDeleteParams {
  ids: number[]; // 删除的文件id列表
}

// 探测点管理-数据集文件列表
export const getDetectionPointDataSetFileList = async (
  params: DetectionPointDataSetFileListParams
): Promise<DetectionPointDataSetFileListResponse> => {
  try {
    const response = await request.get('/GIS/GISDetectionPointDataSetFile', {
      params
    });
    return response.data;
  } catch (error) {
    console.error('获取探测点数据集文件列表失败:', error);
    throw error;
  }
};

// 探测点管理-数据集文件新增/批量新增
export const createDetectionPointDataSetFile = async (
  params: DetectionPointDataSetFileCreateParams
): Promise<CommonResponse> => {
  try {
    const response = await request('/GIS/GISDetectionPointDataSetFileCreate', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('新增探测点数据集文件失败:', error);
    throw error;
  }
};

// 探测点管理-数据集文件删除/批量删除
export const deleteDetectionPointDataSetFile = async (
  params: DetectionPointDataSetFileDeleteParams
): Promise<CommonResponse> => {
  try {
    const response = await request('/GIS/GISDetectionPointDataSetFileDelete', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('删除探测点数据集文件失败:', error);
    throw error;
  }
};

// 巡视数据查询相关接口

// 巡视区数据类型
export interface InspectionArea {
  inspection_area_name: string;
  inspection_area_id: number;
  data_set_list: string[]; // API实际返回的是字符串数组
}

// 巡视数据查询树参数
export interface PatrolDataSearchTreeParams {
  planet_id: number;
}

// 巡视数据查询树响应
export interface PatrolDataSearchTreeResponse {
  code: number;
  msg: string;
  data: InspectionArea[];
}

// 探测点数据类型（按照新接口定义）
export interface PatrolDetectionPoint {
  id: number;
  create_time: string;
  update_time: string;
  detection_strat_time: string;  // 探测开始时间
  detection_end_time: string;    // 探测结束时间
  planet_id: number;
  detection_name: string;        // 探测点名称
  detection_num: string;         // 探测点编号
  center_latitude: number;       // 中心纬度
  center_longitude: number;      // 中心经度
  is_special: number;            // 是否特殊点 0非特殊点 非0特殊点
  data_file_list: {
    id: number;
    inspection_area_id: number;  // 数据区域id
    detection_point_id: number; // 探测点id
    data_set_id: number;         // 数据集id
    create_time: string;
    update_time: string;
    planet_id: number;
    file_name: string;           // 文件名称
    file_path: string;          // 文件路径
    file_sizes: number;
    task: string;               // 任务
    dm_zhname: string;          // 载荷
    data_leve: string;          // 数据等级
  }[];
}

// 巡视数据查询探测点文件参数
export interface PatrolDataSearchDetectionPointFileParams {
  planet_id: number;
  inspection_area_id: number;
  data_set_name?: string; // 非必传，传值则按目标值过滤
}

// 巡视数据查询探测点文件响应
export interface PatrolDataSearchDetectionPointFileResponse {
  code: number;
  msg: string;
  data: PatrolDetectionPoint[];
}

// 获取巡视数据查询树
export const getPatrolDataSearchTree = async (
  params: PatrolDataSearchTreeParams
): Promise<PatrolDataSearchTreeResponse> => {
  try {
    const response = await request('/GIS/GISInspectDataSearchTree', {
      method: 'GET',
      params
    });
    // 转换经纬度字段为数字类型
    if (response.data?.data) {
      response.data.data = response.data.data.map((area: any) => ({
        ...area,
        detection_point_list: area.detection_point_list?.map((dp: any) => ({
          ...dp,
          center_latitude: typeof dp.center_latitude === 'string' ? parseFloat(dp.center_latitude) : dp.center_latitude,
          center_longitude: typeof dp.center_longitude === 'string' ? parseFloat(dp.center_longitude) : dp.center_longitude,
        })),
      }));
    }
    return response.data;
  } catch (error) {
    console.error('获取巡视数据查询树失败:', error);
    throw error;
  }
};

// 获取巡视数据查询探测点文件
export const getPatrolDataSearchDetectionPointFile = async (
  params: PatrolDataSearchDetectionPointFileParams
): Promise<PatrolDataSearchDetectionPointFileResponse> => {
  try {
    const response = await request.get('/GIS/GISInspectDataSearchDetectionPointFile', {
      params
    });
    // 转换经纬度字段为数字类型
    if (response.data?.data) {
      response.data.data = response.data.data.map((item: any) => ({
        ...item,
        center_latitude: typeof item.center_latitude === 'string' ? parseFloat(item.center_latitude) : item.center_latitude,
        center_longitude: typeof item.center_longitude === 'string' ? parseFloat(item.center_longitude) : item.center_longitude,
      }));
    }
    return response.data;
  } catch (error) {
    console.error('获取巡视数据查询探测点文件失败:', error);
    throw error;
  }
};

// 空间数据管理文件接口
export interface GISDataAreaFileItem {
  id: number;
  user_id: number;
  file_name: string;
  file_path: string;
  create_time: string;
  data_size: number;
  task: string;
  dm_zhname: string;
  data_level: string;
  area_name: string; // 空间名字
  left_latitude: number;
  left_longitude: number;
  right_latitude: number;
  right_longitude: number;
}

export interface GISDataAreaFileListParams {
  planet_id: number;
  tree_uuid: string;
  file_name?: string;
  dm_zhname?: string;
  data_level?: string;
  create_time__lte?: string;
  create_time__gte?: string;
  page?: number;
  page_size?: number;
}

export interface GISDataAreaFileListResponse {
  code: number;
  msg: string;
  data: {
    count: number;
    list: GISDataAreaFileItem[];
    page: number;
    pages: number;
    page_size: number;
  };
}

// 获取空间数据管理文件列表
export const getGISDataAreaFileList = async (
  params: GISDataAreaFileListParams
): Promise<GISDataAreaFileListResponse> => {
  try {
    const response = await request.get('/GIS/GISDataAreaFile', {
      params
    });
    return response.data;
  } catch (error) {
    console.error('获取空间数据管理文件列表失败:', error);
    throw error;
  }
};

// 空间数据管理文件新增/批量增加参数
export interface GISDataAreaFileCreateParams {
  planet_id: number;
  tree_uuid: string;
  files: Array<{
    data_type: string;
    product_id: number;
  }>;
}

// 空间数据管理文件新增/批量增加响应
export interface GISDataAreaFileCreateResponse {
  code: number;
  msg: string;
  data: {};
}

// 空间数据管理文件新增/批量增加
export const createGISDataAreaFile = async (
  params: GISDataAreaFileCreateParams
): Promise<GISDataAreaFileCreateResponse> => {
  try {
    const response = await request('/GIS/GISDataAreaFileCreate', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('空间数据管理文件新增失败:', error);
    throw error;
  }
};

// 空间数据管理文件坐标更新参数（坐标和区域名称）
export interface GISDataAreaFileUpdateParams {
  id: number; // 文件id
  area_name: string; // 空间名字
  left_latitude: number;
  left_longitude: number;
  right_latitude: number;
  right_longitude: number;
}

// 空间数据管理文件坐标更新响应
export interface GISDataAreaFileUpdateResponse {
  code: number;
  msg: string;
  data: {};
}

// 空间数据管理文件坐标更新
export const updateGISDataAreaFile = async (
  params: GISDataAreaFileUpdateParams
): Promise<GISDataAreaFileUpdateResponse> => {
  try {
    const response = await request('/GIS/GISDataAreaFileUpdate', {
      method: 'POST',
      data: params,
    });
    return response.data;
  } catch (error) {
    console.error('空间数据管理文件坐标更新失败:', error);
    throw error;
  }
};

// 空间数据管理文件删除/批量删除参数
export interface GISDataAreaFileDeleteParams {
  tree_uuid: string;
  file_ids: number[];
}

// 空间数据管理文件删除/批量删除响应
export interface GISDataAreaFileDeleteResponse {
  code: number;
  msg: string;
  data: {};
}

// 空间数据管理文件删除/批量删除
export const deleteGISDataAreaFile = async (
  params: GISDataAreaFileDeleteParams
): Promise<GISDataAreaFileDeleteResponse> => {
  try {
    const response = await request('/GIS/GISDataAreaFileDelete', {
      method: 'POST',
      data: params
    });
    return response.data;
  } catch (error) {
    console.error('空间数据管理文件删除失败:', error);
    throw error;
  }
};

// 空间数据管理数据及文件导入（接口107）
export interface GISDataAreaFileImportParams {
  file: File;
  planet_id: number;
  tree_uuid: string;
}

export const gisDataAreaFileImport = async (
  params: GISDataAreaFileImportParams
): Promise<CommonResponse> => {
  try {
    const formData = new FormData();
    formData.append('file', params.file);
    formData.append('planet_id', params.planet_id.toString());
    formData.append('tree_uuid', params.tree_uuid);

    const response = await request('/GIS/GISDataAreaFileImport', {
      method: 'POST',
      data: formData,
      headers: {
        'Content-Type': 'multipart/form-data',
      },
    });
    return response.data;
  } catch (error) {
    console.error('空间数据管理数据及文件导入失败:', error);
    throw error;
  }
};

// 探测点管理巡视区相关接口（接口114）
export interface PatrolInspectionAreaItem {
  id: number;
  plance_id: number; // 注意：接口返回的是plance_id，可能是拼写错误
  inspection_area_name: string; // 数据区域名称
  task: string; // 探测任务
  create_time: string; // 创建时间
  left_latitude: number;
  left_longitude: number;
  right_latitude: number;
  right_longitude: number;
  base_img_level: number; // tile层级
  base_image_path: string; // 底图地址
}

export interface PatrolInspectionAreaListParams {
  planet_id: number;
  page?: number;
  page_size?: number;
}

export interface PatrolInspectionAreaListResponse {
  code: number;
  msg: string;
  data: {
    count: number;
    list: PatrolInspectionAreaItem[];
    page: number;
    pages: number;
    page_size: number;
  };
}

// 获取探测点管理巡视区列表
export const getPatrolInspectionAreaList = async (
  params: PatrolInspectionAreaListParams
): Promise<PatrolInspectionAreaListResponse> => {
  try {
    const response = await request.get('/GIS/GISDetectionPointInspectionArea', {
      params
    });
    return response.data;
  } catch (error) {
    console.error('获取探测点管理巡视区列表失败:', error);
    throw error;
  }
};

// 新的下载接口类型定义

// 单文件下载参数
export interface SingleFileDownloadParams {
  data_type: string; // 数据类型，如 'DmSpinfo'
  product_id: number; // 产品ID
}

// 批量下载订单单文件下载参数
export interface BatchOrderFileDownloadParams {
  download_file_id: number; // 批量下载订单中单文件下载的ID
}

// 多文件打包下载参数
export interface MultiFileDownloadParams {
  query_params: Record<string, any>; // 查询的条件加时间戳
  is_gis: boolean; // 是否为GIS下载
  is_favorites: boolean; // 是否为收藏夹中下载
  files: Array<{
    data_type: string; // 数据类型
    product_id: number; // 产品ID
  }>;
}

// 多文件打包下载响应
export interface MultiFileDownloadResponse {
  code: number;
  msg: string;
  data: {
    order_num: string; // 订单号
    order_id: number; // 订单ID
    download_path: string; // 下载地址
  };
}

// 单文件下载接口
export const downloadSingleFile = async (params: SingleFileDownloadParams): Promise<Blob> => {
  try {
    const response = await request.get('/Management/Download', {
      params,
      responseType: 'blob'
    });
    return response.data;
  } catch (error) {
    console.error('单文件下载失败:', error);
    throw error;
  }
};

// 批量下载订单单文件下载接口
export const downloadBatchOrderFile = async (params: BatchOrderFileDownloadParams): Promise<Blob> => {
  try {
    const response = await request.get('/Management/Download', {
      params,
      responseType: 'blob'
    });
    return response.data;
  } catch (error) {
    console.error('批量下载订单单文件下载失败:', error);
    throw error;
  }
};

// 多文件打包下载接口
export const downloadMultiFiles = async (params: MultiFileDownloadParams): Promise<MultiFileDownloadResponse> => {
  try {
    const response = await request.post('/Management/DownloadOrder', params);
    return response.data;
  } catch (error) {
    console.error('多文件打包下载失败:', error);
    throw error;
  }
};

// 空间数据管理全部添加参数
export interface GISDataAreaFileCreateAllParams {
  planet_id: number;
  tree_uuid: string;
  task?: string;
  data_type?: string;
  dm_zhname?: string;
  work_mode?: string;
  data_key?: string;
  data_level?: string;
  version_num?: string;
  station?: string;
  track_num_turns?: number;
  track_num_turns__lte?: number;
  track_num_turns__gte?: number;
  collection_time?: string;
  collection_time__lte?: string;
  collection_time__gte?: string;
  archive_time?: string;
  archive_time__lte?: string;
  archive_time__gte?: string;
}

// 空间数据管理全部添加响应
export interface GISDataAreaFileCreateAllResponse {
  code: number;
  msg: string;
  data: {};
}

// 空间数据管理全部添加接口
export const createGISDataAreaFileAll = async (
  params: GISDataAreaFileCreateAllParams
): Promise<GISDataAreaFileCreateAllResponse> => {
  try {
    const response = await request.get('/Management/GISDataAreaFileCreateAll', {
      params
    });
    return response.data;
  } catch (error) {
    console.error('空间数据管理全部添加失败:', error);
    throw error;
  }
};

// 探测点管理数据集文件全部添加参数
export interface DetectionPointDataSetFileCreateAllParams {
  planet_id: number;
  inspection_area_id: number;
  detection_point_id: number;
  data_set_id: number;
  task?: string;
  data_type?: string;
  dm_zhname?: string;
  work_mode?: string;
  data_key?: string;
  data_level?: string;
  version_num?: string;
  station?: string;
  track_num_turns?: number;
  track_num_turns__lte?: number;
  track_num_turns__gte?: number;
  collection_time?: string;
  collection_time__lte?: string;
  collection_time__gte?: string;
  archive_time?: string;
  archive_time__lte?: string;
  archive_time__gte?: string;
}

// 探测点管理数据集文件全部添加响应
export interface DetectionPointDataSetFileCreateAllResponse {
  code: number;
  msg: string;
  data: {};
}

// 探测点管理数据集文件全部添加接口
export const createDetectionPointDataSetFileAll = async (
  params: DetectionPointDataSetFileCreateAllParams
): Promise<DetectionPointDataSetFileCreateAllResponse> => {
  try {
    const response = await request.get('/Management/GISDetectionPointDataSetFileCreateAll', {
      params
    });
    return response.data;
  } catch (error) {
    console.error('探测点管理数据集文件全部添加失败:', error);
    throw error;
  }
};

// 获取Tile瓦片图接口参数
export interface GetTileParams {
  planet_id: number;
  tile_tag: 'planet' | 'north' | 'south' | 'inspection'; // 只校验过滤这4个值
  inspection_area_id?: number; // tile_tag为inspection时必传
  level: number;
  row: number;
  col: number;
}

// 获取Tile瓦片图接口（返回图片blob）
export const getPlanetTile = async (params: GetTileParams): Promise<Blob> => {
  try {
    const response = await request.get('/GIS/GISPlanetGetTile', {
      params,
      responseType: 'blob'
    });
    return response.data;
  } catch (error) {
    console.error('获取瓦片图失败:', error);
    throw error;
  }
};